jQuery(document).ready(function($) {
	var PC = $(window).width() > 992,
        winWidth = $(window).width(),
        winHeight = $(window).height();

    function sameHeight(obj){
        var arrayHeight = new Array();
        for (var i = 0; i < obj.length; i++) {
            arrayHeight.push(obj.eq(i).find('p').height())
        }
        var max = Math.max.apply(null, arrayHeight);
        obj.find('p').height(max)
    }


    // header--------------------------------------------------------------------------------------------
    if(PC){
        var headerHeight = $('.header').outerHeight();
        $('.header li').hover(function(){
            if($(this).find('.hover').length){
                var subNavheight = $(this).find('.hover').outerHeight();
                $('.header .nav_bg').height(subNavheight + headerHeight).addClass('active');
                if($('.header').attr('data-bg')){
                    $('.header').removeClass('black');
                }
            }
        },function(){
            $('.header .nav_bg').height(0).removeClass('active');
            if($('.header').attr('data-bg')){
                $('.header').addClass('black');
            }
        });
		
		
    }else{
        $('.header').append('<div class="mNavBtn"><span class="line1"></span><span class="line2"></span><span class="line3"></span></div>');
        $('.mNavBtn').click(function () {
            $(this).toggleClass('active');
            $('.header .nav').toggleClass('active');
        });
        $('.header li').each(function(){
            if($(this).find('.hover').length){
                $(this).append('<i></i>');
                $(this).find('a.single').removeAttr('href');
                $(this).find('a').click(function(){
                    $(this).parent('li').toggleClass('open').siblings().removeClass('open');
                })
            }
        })
        $(window).scroll(function(){
            if($(this).scrollTop() > 10){
                $('.header').addClass('m');
            }else{
                $('.header').removeClass('m');
            }
        })
    }
    $('.js_search_btn').click(function(){
        $('.header').addClass('bg_black');
        $(this).parents('.item').addClass('active');
        $('.fixed_search').addClass('active');
    })
    $('.js_search_close').click(function(){
        $('.header').removeClass('bg_black');
        $(this).parents('.item').removeClass('active');
        $('.fixed_search').removeClass('active');
    })

    // index--------------------------------------------------------------------------------------------
    if(PC && $('#fullpage') && $(".indexPage").size()>0){
      debugger;
        $('#fullpage').fullpage({
            verticalCentered: false,
            normalScrollElements: '.fixed_search',
            anchors: ['1', '2', '3', '4', '5'],
            navigation: false,
            menu: '#menu',
            css3: true,
            easing: 'linear',
            // easingcss3: 'cubic-bezier(0.86, 0, 0.07, 1)',
            scrollingSpeed: 1000,
            afterLoad: function(anchorLink, index){
                if(index == 1 || index == 2 || index == 3 || index == 4){
                    $('.header').removeClass('hide');
                }
                if(index == 2){
                    $('.header').addClass('black').attr('data-bg','black');
                }else{
                    $('.header').removeClass('black').removeAttr('data-bg')
                }
            },
            onLeave: function(index, nextIndex, direction){
                if(index == 2 || index == 3 || index == 4 || index == 5 && direction == 'up'){
                    $('.js_index_banner .slick-current video')[0].play();
                }
                if(index ==1 || index == 2 || index == 3 || index == 4){
                    $('.header').addClass('hide')
                }
                if(index == 1 && direction == 'down'){
                    $('.section2.c_cepe .big_box,.section2.c_cepe .small_box').addClass('come_in')
                }
                if(index == 2 && direction == 'down'){
                    $('.section3.c_cepe .big_box,.section3.c_cepe .small_box').addClass('come_in')
                }
                if(index == 4 && direction == 'down'){
                    $('#menu').fadeOut();
                }else{
                    $('#menu').fadeIn();
                }
            }
        });
    }
    var i = 0,
        canClick = true,
        move = true;
    if(winWidth/winHeight>1.78){
        $(".js_index_banner video").css({
            'width': '100%',
            'height': 'auto '
        });
    }else{
        $(".js_index_banner video").css({
            'height': '100%',
            'width': 'auto'
        });
    }
    $('.js_index_banner').slick({
        arrows: false,
        infinite: false,
        responsive:[
            {
                breakpoint: 992,
                settings:{
                    autoplay: true,
                    autoplaySpeed: 8000,
                }
            }
        ]
    })
    if(PC){
        $('.js_index_banner').init('slick',function(){
            indexBannerVideo();
        })
        $('.js_index_banner').on('afterChange', function(event, slick, currentSlide, nextSlide){
            indexBannerVideo();
        });
    }else{
        $('.js_index_banner video').remove();
        $('.js_index_banner').on('afterChange', function(event, slick, currentSlide, nextSlide){
            i = currentSlide;
            indexBannerChange();
        });
    }
    function indexBannerVideo(){
        $('.js_index_banner .video_process').stop(true).removeAttr('style');
        $('.js_index_banner .item video').removeAttr('id src')
        var videoSrc = $('.js_index_banner .slick-current').attr('data-href');
        $('.js_index_banner .slick-current video').attr({
            'src': videoSrc,
            'id':'video'
        })
        var _video = document.getElementById("video");
        // $('.js_index_banner .slick-current video')[0].load();
        if($('.js_index_banner_videobtn').hasClass('pause')){
            $('.js_index_banner .slick-current video')[0].play();
            $('.js_index_banner .slick-current video')[0].addEventListener('canplaythrough', function(event){
                if(this.duration){
                    $('.js_index_banner .slick-current .video_process').animate({
                        width: '100%'
                    }, this.duration*1000)
                }
            })
        }else{
            $('.js_index_banner .slick-current video')[0].addEventListener('canplaythrough', function(event){
                if(this.duration){
                    $('.js_index_banner .slick-current .video_process').stop(true);
                }
            })
        }
        _video.addEventListener("ended",function(){
            i = $(this).parents('.item').index()+1;
            if(i > 2){
                i = 0;
            }
            indexBannerChange();
            $('.js_index_banner').slick('slickGoTo', i);
        })
    }
    $('.js_index_banner_prev').click(function(){
        if(canClick){
            i--;
            if(i < 0){
                i = 0;
                return;
            }
            canClick = false;
            indexBannerChange();
            $('.js_index_banner').slick('slickGoTo', i);
            setTimeout(function(){
                canClick = true;
            }, 800)
        }
    })
    $('.js_index_banner_next').click(function(){
        if(canClick){
            i++;
            if(i > 2){
                i = 2;
                return;
            }
            canClick = false;
            indexBannerChange();
            $('.js_index_banner').slick('slickGoTo', i);
            setTimeout(function(){
                canClick = true;
            }, 800)
        }
    })
    function indexBannerChange(){
        $('.js_index_banner_currnum').text(i+1);
        $('.js_index_banner_li li').eq(i).addClass('active').siblings().removeClass('active');
    }
    $('.js_index_banner_videobtn').click(function(){
        $(this).hasClass('play')?$(this).removeClass('play').addClass('pause'):$(this).removeClass('pause').addClass('play');
        if(PC){
            $(this).hasClass('play')?$('.js_index_banner .slick-current video')[0].pause():$('.js_index_banner .slick-current video')[0].play();
            $('.js_index_banner .slick-current video')[0].addEventListener("pause",function(){
                if(this.duration){
                    $('.js_index_banner .slick-current .video_process').stop(true);
                }
            })
            $('.js_index_banner .slick-current video')[0].addEventListener("play",function(){
                if(this.duration){
                    $('.js_index_banner .slick-current .video_process').animate({
                        width: '100%'
                    }, (this.duration - this.currentTime)*1000)
                }
            })
        }
    })


    if(PC){
        var timer,
            s = 0,
            canMove = true,
            num = $('.js_index_slick1 .item').length;
        timer = setInterval(picChange,8000);
        function picChange(){
            s++;
            if(s > num - 1){
                s = 0;
                $('.js_index_slick2').slick('slickGoTo',1);
            }
            var n = parseInt(s / 7);
            $('.js_index_slick2').slick('slickGoTo',n*7+1);
            picMove();
        }
        function picMove(){
            $('.js_index_slick2 .item').eq(s).addClass('active').siblings().removeClass('active');
            $('.js_index_slick1 .item').eq(s).addClass('next');
            setTimeout(function(){
                $('.js_index_slick1 .item.active').addClass('left');
                $('.js_index_slick1 .item').eq(s).addClass('left')
            },20)
            setTimeout(function(){
                $('.js_index_slick1 .item.active').removeClass('active left')
                $('.js_index_slick1 .item.next').addClass('active').removeClass('next left')
            }, 600)
        }
        $('.js_index_slick2 .item').click(function(){
            if(!$(this).hasClass('active') && canMove){
                clearInterval(timer);
                setTimeout(function(){
                    timer = setInterval(picChange,8000);
                })
                $(this).addClass('active').siblings().removeClass('active');
                if($(this).index() > s){
                    s = $(this).index();
                    $('.js_index_slick1 .item').eq(s).addClass('next');
                    setTimeout(function(){
                        $('.js_index_slick1 .item.active').addClass('left');
                        $('.js_index_slick1 .item').eq(s).addClass('left')
                    },20)
                    setTimeout(function(){
                        $('.js_index_slick1 .item.active').removeClass('active left')
                        $('.js_index_slick1 .item.next').addClass('active').removeClass('next left')
                    }, 600)
                }else{
                    s = $(this).index();
                    $('.js_index_slick1 .item').eq(s).addClass('prev');
                    setTimeout(function(){
                        $('.js_index_slick1 .item.active').addClass('right');
                        $('.js_index_slick1 .item').eq(s).addClass('right')
                    },20)
                    setTimeout(function(){
                        $('.js_index_slick1 .item.active').removeClass('active right')
                        $('.js_index_slick1 .item.prev').addClass('active').removeClass('prev right')
                    }, 600)
                }
                canMove = false;
                setTimeout(function(){
                    canMove = true;
                }, 600)
            }
        })
    }else{
        $('.js_index_slick2 .item').removeClass('active')
        $('.js_index_slick1').slick({
            infinite: true,
            arrows: false,
            slidesToShow: 1,
            slidesToScroll: 1,
            asNavFor: '.js_index_slick2',
            autoplay: true,
            autoplaySpeed: 8000,
        })
    }
    $('.js_index_slick2').slick({
        infinite: false,
        slidesToShow: 7,
        slidesToScroll: 7,
        // focusOnSelect: true,
        speed: 600,
        responsive:[
            {
                breakpoint: 992,
                settings:{
                    infinite: true,
                    slidesToShow: 3,
                    slidesToScroll: 3,
                    arrows: false,
                    focusOnSelect: true,
                    asNavFor: '.js_index_slick1',
                    centerMode: true,
                    centerPadding: '0',
                }
            }
        ]
    })
	
	//内页
	//图片背景方式展示
	if($(".bgImg").size()>0){
	$(".bgImg").each(function(i){$(".bgImg").eq(i).css("background-image","url("+$(this).find("img").attr("src")+")")});
	}
	
	//品牌切换
	$(".m2busBs").click(function(){
		$(".m2busChangeCon").removeClass("on");
		$(".m2busChangeCon").eq($(".m2busBs").index(this)).addClass("on");
		$(this).addClass("on").siblings(".m2busBs").removeClass("on");
		});
		
	//关于我们 了解详情
	if($('#fullpage') && $(".aboutPage").size()>0){
        $('#fullpage').fullpage({
            verticalCentered: false,
            normalScrollElements: '.fixed_search',
            anchors: ['1', '2', '3', '4', '5', '6', '7'],
            navigation: false,
            css3: true,
            easing: 'linear',
            // easingcss3: 'cubic-bezier(0.86, 0, 0.07, 1)',
            scrollingSpeed: 1000,
            afterLoad: function(anchorLink, index){
                if(index == 1 || index == 2 || index == 3 || index == 4 || index == 5 || index == 6 || index == 7){
                    $('.header').removeClass('hide');
                }
				$(".menu2_a").removeClass("on");
				$(".menu2_a").eq(index-2).addClass("on");
				if(index == 2){
					$(".abt-section1").addClass("active2");
				}
				if(index == 3){
					$(".abt-section2").addClass("active2");
				}
				if(index == 4){
					$(".abt-section3").addClass("active2");
				}
				if(index == 5){
					$(".abt-section4").addClass("active2");
				}
				if(index == 6){
					$(".abt-section5").addClass("active2");
				}
				if(index == 7){
					$(".abt-section6").addClass("active2");
				}				
				if(index == 1 || index == 8){
                    $("#menu2").fadeOut(300);
                }else{
                    $("#menu2").fadeIn(300);
                }
            },
            onLeave: function(index, nextIndex, direction){
                if(index ==1 || index == 2 || index == 3 || index == 4 || index == 5 || index == 6 || index == 7){
                    $('.header').addClass('hide')
                }
                if(index==7 && direction == 'down'){
					$("#menu2").fadeOut(300);
					}
				if(index==2 && direction == 'up'){
					$("#menu2").fadeOut(300);
					}
            }
        });
    }
	
	//页面滚动
	if($(".m2abtTop").size()>0){
		var topHeight = $(window).height();
            $(".m2abtTop .arrow").click(function(){
			$("body,html").animate({"scrollTop":topHeight},800);
			});
		if($('.m2abtTop').size()>0){
			$('.m2abtTop').waypoint(function(direction){if(direction==='down'){}else{
				$('.header').addClass('hide');
				$("body,html").stop().animate({"scrollTop":0},500);
				$('.header').removeClass('bg_black');
				setTimeout(function(){$('.header').removeClass('hide');},1000);
			}},{offset:"-90%" });
			$('.m2abtTop').waypoint(function(direction){if(direction==='down'){
			$("body,html").stop().animate({"scrollTop":topHeight},500);
			$('.header').addClass('hide');
			setTimeout(function(){$('.header').removeClass('hide');$('.header').addClass('bg_black');},1000);
			}},{offset:"-10%" });
		}
	}else{
		//导航下滑改变深色
		$(window).scroll(function(){
			if($(".min2Body").size()){
				if($(window).scrollTop()>10){
					$('.header').addClass('bg_black');
					}else{
						$('.header').removeClass('bg_black');
						}
				}
			});
		}
	
	 //子页面分享工具
	 if($(".articleTools").size()){
		 //位置
		 $(window).scroll(function(){
			 if($(window).scrollTop()>($(".arTools_line").offset().top-200)){
				 $(".articleTools").fadeOut(100);
				 }else{
					 $(".articleTools").fadeIn(100);
					 }
		 });
		 //分享弹出/隐藏
		 $(".arSreBtn").click(function(event){
			 event.stopPropagation();
			 $(".arShareBox").show();
			 });
		 $(document).click(function(){
			   $(".arShareBox").hide();
		 });


			 
	 }
	 
	 
	 //媒体分享隐藏/显示
		 $(".m2nShareBtn").click(function(event){
			 event.stopPropagation();
			 $(".m2nShareBox").hide();
			 $(this).next(".m2nShareBox").show();
			 });
		 $(document).click(function(){
			   $(".m2nShareBox").hide();
		 });

	
})

//分页
$(".page li:last-child").remove();
$(".page li:first").addClass("page_prev").find("a").text("‹");
$(".page li:last").addClass("page_next").find("a").text("›");

//复制功能定义函数
window.Clipboard = (function(window, document, navigator) {
  var textArea,
      copy;

  // 判断是不是ios端
  function isOS() {
    return navigator.userAgent.match(/ipad|iphone/i);
  }
  //创建文本元素
  function createTextArea(text) {
    textArea = document.createElement('textArea');
    textArea.innerHTML = text;
    textArea.value = text;
	textArea.className = "opacityTextarea";
    document.body.appendChild(textArea);
  }
  //选择内容
  function selectText() {
    var range,
        selection;

    if (isOS()) {
      range = document.createRange();
      range.selectNodeContents(textArea);
      selection = window.getSelection();
      selection.removeAllRanges();
      selection.addRange(range);
      textArea.setSelectionRange(0, 999999);
    } else {
      textArea.select();
    }
  }

//复制到剪贴板
  function copyToClipboard() {        
    try{
      if(document.execCommand("Copy")){
        alert("复制成功！");  
      }else{
        alert("复制失败！请手动复制！");
      }
    }catch(err){
      alert("复制错误！请手动复制！")
    }
    document.body.removeChild(textArea);
  }

  copy = function(text) {
    createTextArea(text);
    selectText();
    copyToClipboard();
  };

  return {
    copy: copy
  };
})(window, document, navigator);
//使用函数
if($(".arCopy").size()>0){
var url = window.location.href;
$(".arCopy").on("tap",function(){
  var  val = url;
  Clipboard.copy(val);
});
$(".arCopy").on("click",function(){
  var  val = url;
  Clipboard.copy(val);
});
}


